package com.shaoshaohuo.app.utils;

import com.shaoshaohuo.app.entity.Specification;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 产品规格 数据处理
 * Created by cao on 2016/2/26.
 */
public class SpecificationDataUtil {


    public static Map<Specification,List<Specification>> list2map(List<Specification> list) {
        Map<Specification,List<Specification>> map = new HashMap<>();
        if (list != null && !list.isEmpty()) {
            for (Specification specification : list) {
                if (!"0".equals(specification.specification_name) && !map.containsKey(specification)) {
                    map.put(specification, new ArrayList<Specification>());
                }
            }

            Set<Specification> keySet = map.keySet();
            if (keySet != null && !keySet.isEmpty()) {
                for (Specification specification : list) {
                    for (Specification key : keySet) {
                        if (key.id.equals(specification.t_pid)) {
                            map.get(key).add(specification);
                        }
                    }
                }
            }
        }

        return map;
    }
}
